/*
题目描述：不用加减乘除左加法
方法：
位运算
 */
public class E65 {
    public static void main(String[] args) {
        int num1 = 9;
        int num2 = 3;
        System.out.println(Add(num1, num2));
    }

    public static int Add(int num1,int num2) {
        while(num2 != 0){
            int temp = num1 ^ num2;
            num2 = (num1 & num2) << 1;
            num1 = temp;
        }
        return num1;
    }
}
/*
5 + 7 = 12
step1:
 1 0 1
^1 1 1
=0 1 0
-->temp
step2:
 1 0 1
&1 1 1
=1 0 1
shift << 1
num2 = 1 0 1 0
num1 = temp = 0 1 0
step3:
loop step1;
------------------------
step1:
 0 0 1 0
^1 0 1 0
=1 0 0 0
-->temp
step2:
 0 0 1 0
&1 0 1 0
=0 0 1 0
shift << 1
num2 = 0 1 0 0

step1:
 1 0 0 0
^0 1 0 0
=1 1 0 0
step2:
 1 0 0 0
&0 1 0 0
=0 0 0 0
shift << 1
num2 = 0 0 0 0
now num1 = temp = 1 1 0 0
12
 */